#include <bits/stdc++.h>
using namespace std;

template<typename T> inline void read(T &x)
{
	x = 0;
	T f = 1;char ch = getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
		{
			f = -1,ch = getchar();
			break;
		}
		ch = getchar();
	}
	while(ch>='0'&&ch<='9')
		x = (x<<3)+(x<<1)+ch-48,ch = getchar();
	x*=f;
}
template<typename T = int> inline T read()
{
	T x;read(x);return x;
}
template<typename T> void write(T x)
{
    if(x<0) x = -x,putchar('-');
    if(x>9) write(x/10);
    putchar(x%10+48);
}
template<typename T> inline void writen(T x)
{
    write(x);
	putchar(10);
}
const int N = 15;
int n,a[N],b[N];
map<vector<int>,bool> res;
vector<int> tmp;
void dfs(int x,int y)
{
    if(x==n&&y==n) return res[tmp] = 1,void();
    if(x<n) tmp.push_back(b[y]),dfs(x+1,y),tmp.pop_back();
    if(y<n) tmp.push_back(a[x]),dfs(x,y+1),tmp.pop_back();
}
signed main()
{
	freopen("zha.in","r",stdin);
	freopen("zha.out","w",stdout);
    read(n);
    for(int i = 1;i<=n;i++)
        read(a[i]);
    for(int i = 1;i<=n;i++)
        read(b[i]);
    dfs(1,1);
    write(res.size());
	return 0;
}